package com.cuckoo.mall.test;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.support.annotation.Nullable;

import com.bgn.baseframe.LibLoader;
import com.bgn.baseframe.utils.NotificationHelper;
import com.cuckoo.mall.R;

/**
 * Created by wanglun on 2018/3/8.
 */

public class CancelNoticeService extends Service {
    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate() {
        super.onCreate();
    }

    public int onStartCommand(Intent intent, int flags, int startId) {
        startForeground(NotificationHelper.FOREGROUND_NOTIFICATION_ID, new Notification());
        //发送与KeepLiveService中ID相同的Notification，然后将其取消并取消自己的前台显示
        Notification.Builder builder = new Notification.Builder(this);
        builder.setSmallIcon(R.mipmap.ic_launcher);
        startForeground(NotificationHelper.FOREGROUND_NOTIFICATION_ID, NotificationHelper.getNotification());
        LibLoader.getMainThreadHandler().postDelayed(new Runnable() {
            @Override
            public void run() {
                stopForeground(true);
                NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
                manager.cancel(NotificationHelper.FOREGROUND_NOTIFICATION_ID);
                stopSelf();
            }
        }, 100);
        return super.onStartCommand(intent, flags, startId);
    }

}
